package com.springbootes.controller;

import com.springbootes.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @User 小菜鸡
 * @Data 2020/5/17
 */
@RestController
public class IndexController {

    @Autowired
    private IndexService indexService;

    //restful风格就是将参数直接卸载路径中，普通的参数是在路径后面使用"?"来拼接，restful风格体验更好
    @GetMapping("/parse/{keyword}/{pageCur}/{pageSize}")
    public List<Map<String, Object>> insertData(
            @PathVariable("keyword") String keyword,
            @PathVariable("pageCur")Integer pageCur,
            @PathVariable("pageSize")Integer pageSize) throws Exception {
        List<Map<String, Object>> list = new ArrayList<>();
        boolean insertResult = indexService.insert(keyword);
        if (insertResult){
            list = indexService.select(pageCur,pageSize);
        }
        return list;
    }
}
